home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Looking for semaphore example.
- Date: 1 Apr 1996 08:08:22 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4jov1mINNki@keats.ugrad.cs.ubc.ca>
- References: <4jc5hd$1vlv@ilx018.iil.intel.com> <828220289snz@genesis.demon.co.uk> <4jlc0k$j02@solutions.solon.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4jlc0k$j02@solutions.solon.com>,
- Peter Seebach <seebs@solutions.solon.com> wrote:
- >In article <828220289snz@genesis.demon.co.uk>,
- >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >>>Hi -
- >>>I'm looking for a simple example of implementation of semaphore in C .
- >
- >>Not possible - the C language doesn't support semaphores. You'll have
- >>to go beyond the C language to get this.
- >
- >Nonsense! You'll just need to go beyond the C language to implement
- >semaphores in a useful or meaningful way. :) You could easily implement
- >a semaphore algorithm in C, it just wouldn't matter in pure C, because
- >you'd only ever have the one process.
-
- How would you do it?. A semaphore is by definition a shared object between two
- processes for the purpose of synchronization, and not just some ordinary
- variable. Interprocess communication and synchronization is outside of the
- scope of the C language proper.
-
- By the way, what is the Standard C answer to the test-and-set operation? I
- don't think that there is an atomic test-and-set in the C language, so I don't
- see how you have any hope of implementing a semaphore algorithm in pure C that
- would have any hope of working race-free in a threaded environment. Even
- blocking signals is outside of the scope of standard C, not to mention
- disabling machine interrupts or doing bus locking. Hmm.
- --
-
-